package mo.qmul.gemom;

import java.util.Vector;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
/** COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 * */
public class stateTable {

	JTable table;
	DefaultTableModel model;

	String[] columnNames = {"Namespace","Measurement","State"};

	String[] Measure ={"Idle CPU","Available memory","Maximum bandwidth","Bandwidth utilisation",
	"Paging activity"};
	String[] Ini= {"iCPU","aMEM","bMAX","bUTIL","pACT"};

	public stateTable(){

		model= new DefaultTableModel(columnNames,0);

		table = new JTable(model);

	//	table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

		


	}

	public JTable getTable(){
		return table;
	}


	public void createRow(stateRecord sr)
	{
		Object[] newRow = new Object[3];
		newRow[0] = sr.getNamespace();
		newRow[1] = sr.getMeasure();
		newRow[2] = sr.getnNumofTopic();

		model.addRow(newRow);
	}

	public void deletRow(int rowID)
	{
		if(rowID< model.getColumnCount())
			model.removeRow(rowID);

	}

	public void update(stateRecord sr)
	{
		for(int i=0; i< model.getRowCount(); i++)
		{
			if(model.getValueAt(i, 0).toString().equalsIgnoreCase(sr.getNamespace()))
			{
				model.setValueAt(sr.getnNumofTopic(), i, 2);
			}
		}
		
		
		
	}




}
